import flask
from flask import Blueprint
import db

page_register = Blueprint('page_register', __name__)


@page_register.route('/register', methods=['GET', 'POST'])
def register():
    """
    register page
    :return:
        when method is GET, just return HTML page
        when method is POST, insert info of new user into db
    """
    if flask.request.method == 'GET':
        return flask.render_template('./static/templates/register.html')

    if flask.request.method == 'POST':
        name = flask.request.form.get('name')
        psw = flask.request.form.get('psw')
        cps = flask.request.form.get('cps')
        tel = flask.request.form.get('tel')
        sid = flask.request.form.get('sid')
        vx = flask.request.form.get('vx')
        qq = flask.request.form.get('qq')
        email = flask.request.form.get('email')
        r = db.insert_user(name=name, psw=psw, cps=cps, tel=tel, sid=sid, vx=vx, qq=qq, email=email)
        return r
